package com.spider.gp.schedule;

import com.spider.gp.controller.SpriderController;
import com.spider.gp.dao.Xjb;
import com.spider.gp.dao.XjbDto;
import com.spider.gp.util.JsonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * description:
 *
 * @author clare
 * @date 2022/06/19 08:52
 **/
@EnableScheduling
@Component
@Slf4j
public class XjbSchedule {

    @Autowired
    private XjbDto xjbDto;
    @Autowired
    private SpriderController spriderController;

    @Scheduled(cron = "0 35 23 * * ?")  //
    public void saveZJJE() {
        spriderController.kuaile8();
    }






    @Scheduled(cron = "0 35 9 * * ?")  //
    public void saveXJB() {
        System.out.println("快乐八 选九  4注一倍  ");
        List<Integer> numbers = new ArrayList<>();
        numbers.add(2);
        numbers.add(9);
        numbers.add(10);
        numbers.add(25);
        numbers.add(36);
        numbers.add(45);
        int i = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
        numbers.add(i);
        int i1 = (int) (Math.random() * 80) +1;
        numbers.add(i1);
        int i2 = (int) (Math.random() * 80) +1;
        numbers.add(i2);
//        Collections.sort(numbers);

        Set<Integer> tmpSet = new HashSet<>(numbers);
        if (tmpSet.size() < 9 ){
            tmpSet.add((int) (Math.random() * 80) +1);
            if (tmpSet.size() < 9){
                tmpSet.add((int) (Math.random() * 80) +1);
            }
        }
//        System.out.println(tmpSet);
        Set<Integer> sortSet = new TreeSet<Integer>(Comparator.naturalOrder());
        sortSet.addAll(tmpSet);
        System.out.println(sortSet);

        try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); }

        //第二注
        List<Integer> numbers02  = new ArrayList<>();
        numbers02.add(2);
        numbers02.add(9);
//        numbers02.add(10);
//        numbers02.add(25);
        numbers02.add(36);
//        numbers02.add(45);
        numbers02.add((int) (Math.random() * 80) +1);
        numbers02.add((int) (Math.random() * 80) +1);
        numbers02.add((int) (Math.random() * 80) +1);
        numbers02.add((int) (Math.random() * 80) +1);
        numbers02.add((int) (Math.random() * 80) +1);
        numbers02.add((int) (Math.random() * 80) +1);
//        Collections.sort(numbers02);

        Set<Integer> tmpSet02 = new HashSet<>(numbers02);
        if (tmpSet02.size() < 9 ){
            tmpSet02.add((int) (Math.random() * 80) +1);
            if (tmpSet02.size() < 9){
                tmpSet02.add((int) (Math.random() * 80) +1);
            }
        }

        Set<Integer> sortSet02 = new TreeSet<Integer>(Comparator.naturalOrder());
        sortSet02.addAll(tmpSet02);
        System.out.println(sortSet02);

        try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); }

        //第三注
        List<Integer> numbers03  = new ArrayList<>();
        numbers03.add(4);
        numbers03.add(5);
        numbers03.add(10);
        numbers03.add(25);
        numbers03.add((int) (Math.random() * 80) +1);
        numbers03.add((int) (Math.random() * 80) +1);
        numbers03.add(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        numbers03.add((int) (Math.random() * 80) +1);
        numbers03.add((int) (Math.random() * 80) +1);
//        Collections.sort(numbers03);

        Set<Integer> tmpSet03 = new HashSet<>(numbers03);
        if (tmpSet03.size() < 9 ){
            tmpSet03.add((int) (Math.random() * 80) +1);
            if (tmpSet03.size() < 9){
                tmpSet03.add((int) (Math.random() * 80) +1);
            }
        }
//        System.out.println(tmpSet03);

        Set<Integer> sortSet03 = new TreeSet<Integer>(Comparator.naturalOrder());
        sortSet03.addAll(tmpSet03);
        System.out.println(sortSet03);

        try { TimeUnit.MILLISECONDS.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); }

        //第四注 全随机
        List<Integer> numbers04  = new ArrayList<>();
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add(Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        numbers04.add((int) (Math.random() * 80) +1);
        numbers04.add((int) (Math.random() * 80) +1);


        Set<Integer> tmpSet04 = new HashSet<>(numbers04);
        if (tmpSet04.size() < 9 ){
            tmpSet04.add((int) (Math.random() * 80) +1);
            if (tmpSet04.size() < 9){
                tmpSet04.add((int) (Math.random() * 80) +1);
            }
        }
        Set<Integer> sortSet04 = new TreeSet<Integer>(Comparator.naturalOrder());
        sortSet04.addAll(tmpSet04);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String reportTime = formatter.format(new Date());
        List<Set<Integer>> datas = new ArrayList<>();
        datas.add(sortSet);
        datas.add(sortSet02);
        datas.add(sortSet03);
        datas.add(sortSet04);
        Xjb xjb = Xjb.builder().reportTime(reportTime).content(JsonUtils.obj2String(datas)).fixed("快乐八 选九  4注一倍 ").build();
        xjbDto.insert(xjb);
    }

}








